package com.hesicare.adapter.service.impl;

import com.hesicare.adapter.entity.HisPatient;
import com.hesicare.adapter.service.IParsePatientService;
import com.hesicare.health.service.ISysPatientRecordService;
import com.hesicare.health.service.ISysPatientService;
import com.hesicare.health.worker.DoPatient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author 55097
 */
@Service
public class ParsePatientServiceImpl implements IParsePatientService {

    protected final static Logger log = LoggerFactory.getLogger(ParsePatientServiceImpl.class);

    @Autowired
    private ISysPatientService ISysPatientService;

    @Autowired
    private ISysPatientRecordService ISysPatientRecordService;

    @Autowired
    private DoPatient doPatient;

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    SimpleDateFormat birsimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public void parsePatient(Object obList) {
        if (obList != null) {
            ArrayList<HisPatient> list = (ArrayList<HisPatient>) obList;
            list.stream().forEach(hisPatient -> {
                doPatient.doPatient(hisPatient);
            });
        }
    }

    @Override
    public void parseOutPatient(Object obList) {
        if (obList != null) {
            ArrayList<HisPatient> list = (ArrayList<HisPatient>) obList;
            list.stream().forEach(hisPatient -> {
                doPatient.doPatient(hisPatient);
            });
        }
    }

    @Override
    public void parseClearPatient(Set<String> patientSet) {
        List<String> clearPatient = new ArrayList<>();
        List<String> patientIds = ISysPatientService.selectHisPatientIdByHospitalType();
        for (String id : patientIds) {
            if (!patientSet.contains(id)) {
                clearPatient.add(id);
            }
        }
        if (!clearPatient.isEmpty()) {
            log.info("清除患者列表{}", clearPatient.toString());
            ISysPatientRecordService.updateHisPatientByhospitalizedType(clearPatient);
            ISysPatientService.updateHisPatientByhospitalizedType(clearPatient);
            patientIds.clear();
        }
    }


}

